package VIEW;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DAL.BaseDAO;
import DAL.BaseItemDAO;
import DAL.DoAsapItemDAO;
import DOMAIN.BaseItem;
import DOMAIN.DoAsapItem;

public class DetailDoAsapItemServlet extends HttpServlet {


	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws IOException, ServletException{
	
	
		BaseDAO<DoAsapItem> dao = new DoAsapItemDAO();
		System.out.println(request.getParameter("id"));
		int baseItemId = Integer.parseInt(request.getParameter("id")) ;
		
		request.setAttribute("DoAsapItem", dao.Find(baseItemId));
		request.getRequestDispatcher("DetailDoAsapItem.jsp").forward(request, response);	
	
	}	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws IOException, ServletException{
		BaseDAO<BaseItem> dao = new BaseItemDAO();
		System.out.println(request.getParameter("id"));
		
		int baseItemId = Integer.parseInt(request.getParameter("id")) ;
		
		BaseItem bi = dao.Find(baseItemId);
		bi.SetTitle(request.getParameter("titre"));
		bi.SetDescription(request.getParameter("description"));
		if(request.getParameter("IsActive")!=null)
			bi.SetActive(true);
		else bi.SetActive(false);
		
		if(request.getParameter("IsActionnable")!=null)
			bi.SetActionnable(true);
		else
			bi.SetActionnable(false);
		dao.Update(bi);
	
		doGet(request,response);	
	}	

}
